package cn.lhjl.day06.链表;

class Node {
    private int date;
    private Node next;//存储下一个Node的地址

    public Node() {
    }

    public Node(int date) {
        this.date = date;
    }

    public Node(int date, Node next) {
        this.date = date;
        this.next = next;
    }

    public int getDate() {
        return date;
    }

    public void setDate(int date) {
        this.date = date;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }

    public static void addDate(int value, Node head) {
        Node newNode = new Node(value);
        Node tmp = head;
        while (tmp.next != null) {
            tmp = tmp.next;
        }
        tmp.next = newNode;
    }

    public static void traverse(Node head) {
        while (head != null) {
            System.out.println(head.date);
            head = head.next;
        }
    }

    public static int linkListLength(Node head) {
        int length = 0;
        while (head!=null){
            length++;
            head=head.next;
        }
        return length;
    }
}
